const data=require('./src/mock/index')
// console.log(data)
const bodyParser=require('body-parser')
let auth=""

module.exports={
    devServer:{
        before:(app)=>{
            app.use(bodyParser.json())
            // let auth=Math.random().toString(36).slice(2,6)
           
          
              

            // let auth=
            app.post('/api/data',(req,res)=>{
                const {username,password,authcode}=req.body
                // console.log(authcode,auth)
               let lis=data.find(item=>item.username===username&&item.password===password)
               if(authcode!==auth){
                res.send({
                    code:404,
                    mess:'验证码错误',
                   
                })
               }else if(lis){
                  res.send({
                    code:200,
                    mess:'登录成功',
                    token:111
                  })
               }else{
                   res.send({
                       code:404,
                       mess:'登录失败'
                   })
               }
            })
            // 获取验证码
            app.post('/api/authcode',(req,res)=>{
                auth=Math.floor(Math.random()*(1000-9999+1)+9999)
                // console.log(num)
                res.send({
                    code:200,
                    data:auth
                })
            })
        }
    }
}